package com.plan.dao.logindao.impl;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.plan.dao.hibernate.HebernateInit;
import com.plan.dao.logindao.LoginDao;
import com.plan.login.entity.LoginEntity;

/**
 * 登录注册
 *
 * @author wangzih
 */
@Component("plan_logindao")
public class LoginDaoImpl implements LoginDao {

	public LoginEntity findUser(String id) {
		Session session = HebernateInit.getSession();
		try{
			LoginEntity login = (LoginEntity) session.createCriteria(LoginEntity.class).add(Restrictions.eq("id", id)).uniqueResult();
			return login;
		}finally{
			session.close();
		}
	}

	public void addUser(LoginEntity le) throws Exception{
		Session session = HebernateInit.getSession();
		try{
			Transaction tx = session.beginTransaction();
			session.save(le);
			tx.commit();
		}finally{
			session.close();
		}
		
	}

}
